home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / amos / amcafext.lha / AMCAF_Examples / VecRotSolidLight.AMOS / VecRotSolidLight.amosSourceCode
AMOS Source Code  |  1995-07-14  |  4KB  |  134 lines

  1. ' ************************************* Commands used: 
  2. ' *                                   * Vec Rot Pos        Blitter Clear 
  3. ' *           Amcaf Examples          * Vec Rot Angles     =Qsin 
  4. ' * Vector Rotate Solid + Light V1.1  * Vec Rot Precalc    =Mix Colour 
  5. ' *      Written by Chris Hodges      * =Vec Rot X 
  6. ' *                                   * =Vec Rot Y 
  7. ' ************************************* =Vec Rot Z 
  8. '                          
  9. ' Remove mouse pointer.
  10. Hide 
  11. ' Setup a nice little screen with double buffering 
  12. Screen Open 0,320,256,8,Lowres
  13. Curs Off : Flash Off : Paper 0 : Pen 1 : Cls 
  14. Double Buffer 
  15. Autoback 0
  16. ' Read out how many colours are used, and then their values. 
  17. Restore OBJCOLS
  18. Read NUMCV
  19. Dim CVAL(NUMCV)
  20. For A=1 To NUMCV
  21.   Read CVAL(A)
  22. Next 
  23. ' Read out, how many coords are used.
  24. Restore COORDS
  25. Read NUMCO
  26. ' Dim one field to keep these coords, and a second for the rotated.
  27. Dim CO(NUMCO,2),RC(NUMCO,2)
  28. ' Now read all coords in.
  29. For A=1 To NUMCO
  30.   Read CO(A,0),CO(A,1),CO(A,2)
  31. Next 
  32. ' Then, get the number of shapes the object consists of. 
  33. Restore SHAPES
  34. Read NUMLI
  35. ' Dim a field to hold the four coords. 
  36. Dim LI(NUMLI,4)
  37. ' Get the datas. 
  38. For A=1 To NUMLI
  39.   Read LI(A,0),LI(A,1),LI(A,2),LI(A,3)
  40.   Read LI(A,4)
  41. Next 
  42. ' Set the three angles. Remember that these are non standard angles, 
  43. ' one full rotation is at 1024, not 360! 
  44. AX=0 : AY=512 : AZ=128
  45. Repeat 
  46.   ' Start clearing bitplane 0. 
  47.    Extension_8_121C 0,0
  48.   ' While the blitter is working, use the time to calculate the rotations. 
  49.   ' Move and set the angles. 
  50.   Add AX,5
  51.   Add AY,8
  52.   Add AZ,11
  53.    Extension_8_1138 AX,AY,AZ
  54.   ' Calculate the distances by using a sine-function and the three angles. 
  55.   POSX= Extension_8_1106(AX,300)
  56.   POSY= Extension_8_1106(AY,300)
  57.   POSZ= Extension_8_1106(AZ,500)+1500
  58.   ' Set the camera positions.
  59.    Extension_8_1122 POSX,POSY,POSZ
  60.   ' Now it's time to compute the matrix. 
  61.    Extension_8_1152 
  62.   ' Clear bitplane 1 
  63.    Extension_8_121C 0,1
  64.   ' So let's rotate all coordinates of the field CO()
  65.   For A=1 To NUMCO
  66.     ' Note: You only have to use the vec rot function with parameters once.
  67.     RC(A,0)= Extension_8_1168(CO(A,0),CO(A,1),CO(A,2))+160
  68.     RC(A,1)= Extension_8_1184 +128
  69.     RC(A,2)= Extension_8_11C4 -POSZ
  70.   Next 
  71.   ' Clear bitplane 2 
  72.    Extension_8_121C 0,2
  73.   ' It's time to finally get the polygons to the screen! 
  74.   For A=1 To NUMLI
  75.     ' Get the four coordinates pairs.  
  76.     C1=LI(A,0) : C2=LI(A,1) : C3=LI(A,2) : C4=LI(A,3)
  77.     CO=LI(A,4)
  78.     ' Get the rotated coordinates
  79.     X1=RC(C1,0) : Y1=RC(C1,1)
  80.     X2=RC(C2,0) : Y2=RC(C2,1)
  81.     X3=RC(C3,0) : Y3=RC(C3,1)
  82.     X4=RC(C4,0) : Y4=RC(C4,1)
  83.     ' Use some maths, to see if the plane faces into the camera or into
  84.     ' the back. This formula works ONLY, if the polygon is drawn 
  85.     ' clockwise!   
  86.     DI=(X3-X1)*(Y2-Y1)-(X2-X1)*(Y3-Y1)
  87.     If DI<0
  88.       ' Calculate the new colour value. This time, only simple maths 
  89.       ' is used, and it will not be 100% correct, but it works :)
  90.       Z=-RC(C1,2)-RC(C2,2)-RC(C3,2)-RC(C4,2)
  91.       ' Add or sub from this colour. 
  92.       NC= Extension_8_0EE8(CVAL(CO),$111*Max(Min((Z/16)-13,15),-15),0 To $FFF)
  93.       Colour CO,NC
  94.       ' Draw the polygons in colour CO 
  95.       Ink CO
  96.       Polygon X1,Y1 To X2,Y2 To X3,Y3 To X4,Y4
  97.     End If 
  98.   Next 
  99.   ' Swap the screens to bring the object to view.
  100.   Screen Swap 
  101.   Wait Vbl 
  102. Until Inkey$=Chr$(27) or Mouse Key<>0
  103. Screen Close 0
  104. End 
  105. OBJCOLS:
  106.   Data 6
  107.   Data $F44,$4F4,$FF4,$44F,$F4F,$4FF
  108. '  1_____2   
  109. ' 5/____/| 
  110. ' | |  |6| 
  111. ' |4|__|_|3  
  112. ' |/___|/
  113. ' 8    7 
  114. COORDS:
  115.   Data 8
  116. ' CUBE 
  117.   Data -100,-100,-100
  118.   Data 100,-100,-100
  119.   Data 100,-100,100
  120.   Data -100,-100,100
  121.   Data -100,100,-100
  122.   Data 100,100,-100
  123.   Data 100,100,100
  124.   Data -100,100,100
  125.  
  126. SHAPES:
  127.   Data 6
  128. ' All lines are drawn clockwise. 
  129.   Data 1,2,6,5,1
  130.   Data 4,3,2,1,2
  131.   Data 2,3,7,6,3
  132.   Data 3,4,8,7,4
  133.   Data 4,1,5,8,5
  134.   Data 6,7,8,5,6